<?php

namespace App\Api\Controllers;

use App\Models\Depot;
use App\Models\Notice;
use App\Models\University;
use Dingo\Api\Http\Request;
use Dingo\Api\Routing\Helpers;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\DB;

/**
 * Class SpreadController
 * @package App\Api\Controllers
 * 系统消息
 */
class NoticeController extends Controller
{
    use Helpers;

    /**
     * 名称：检查用户是否有系统消息
     */
    public function index(){
        $user=$this->auth->user();
        $res=Notice::where([['user_id',$user->id],['readed',0]])->count();
        return $this->response->array([
            'status_code'=>200,
            'message'=>'获取数据成功',
            'result'=>$res
        ]);
    }

    public function noticeList(){
        $user=$this->auth->user();
        //更新所有的消息为已读
        DB::table('notice')->where('user_id',$user->id)->update(['readed'=>1]);
        $noticeList=Notice::where('user_id',$user->id)->orderBy('id','desc')->get();
        return $this->response->array([
            'status_code'=>200,
            'message'=>'获取数据成功',
            'result'=>$noticeList
        ]);

    }

}